package com.hl.sfzy.controller;

import com.github.pagehelper.PageInfo;
import com.hl.sfzy.entity.Appointment;
import com.hl.sfzy.service.AppointmentService;
import com.hl.sfzy.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/appointment")
@CrossOrigin
public class AppointmentController {
    @Autowired
    private AppointmentService appointmentService;
    @PostMapping("/insert")
    public R insert(@RequestBody Appointment appointment){
        return R.ok(appointmentService.insert(appointment));
    }
    @PutMapping("/update")
    public R update(@RequestBody Appointment appointment){
        return R.ok(appointmentService.update(appointment));
    }
    @DeleteMapping("/delete")
    public R delete(@RequestParam long id){
        return R.ok(appointmentService.deleteById(id));
    }
    @GetMapping("/select")
    public R selectById(@RequestParam long id){
        return R.ok(appointmentService.selectById(id));
    }
    @GetMapping("/selectAll")
    public R selectAll(){
        List<Appointment> list = appointmentService.getAllList();
        return R.ok(list);
    }
    @GetMapping("/findByPage")
    public R findByPage(@RequestParam(required = false,defaultValue = "1") int pageNum,
                        @RequestParam(required = false,defaultValue = "3") int pageSize,
                        Appointment appointment){
        PageInfo<Appointment> pageInfo=appointmentService.findByPage(pageNum, pageSize, appointment);
        return R.ok(pageInfo);
    }
}
